/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Description: kasan header for LDK
 * Author: Huawei OS Kernel Lab
 * Create: Tue Aug 08 22:09:24 2023
 */
#ifndef __ASM_KASAN_H
#define __ASM_KASAN_H

#ifndef __ASSEMBLY__

#include <linux/linkage.h>
#include <asm/memory.h>
#include <asm/pgtable-types.h>

#define arch_kasan_set_tag(addr, tag)	__tag_set(addr, tag)
#define arch_kasan_reset_tag(addr)	__tag_reset(addr)
#define arch_kasan_get_tag(addr)	__tag_get(addr)

#ifdef CONFIG_LIBLINUX_NATIVE_KASAN
#ifdef CONFIG_KASAN_SW_TAGS
#define KASAN_SHADOW_SCALE_SHIFT 4
#else /* !CONFIG_KASAN_SW_TAGS */
#define KASAN_SHADOW_SCALE_SHIFT 3
#endif /* CONFIG_KASAN_SW_TAGS */

#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
#define KASAN_SHADOW_KMAP_SIZE (UL(1) << (64 - CONFIG_LIBLINUX_KMAP_BITS))
#define KASAN_FREE_PAGE 0xFF  /* page was freed */

void kasan_init(void);
void kasan_poison_shadow(const void *address, size_t size, u8 value);

#else /* !CONFIG_LIBLINUX_NATIVE_KASAN */
static inline void kasan_init(void) { }

#endif /* CONFIG_LIBLINUX_NATIVE_KASAN */
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_KASAN_H */
